<?php
class Managesoftware_Data_Addedaction {
	
	private $database;
	private $secure;
	
	public function __construct(){
		$this->secure = new Core_Data_Secure();
		$this->database = new Core_Driver_MysqlImproved();
	}
	
	public function addValues(array $postVars){
		$postVars = $this->secure->parseData($postVars);
		$name = $postVars['name'];
		$metaTitle = $postVars['meta_title'];
		$accessLevel = $postVars['privileges'];
		$metaKeyrwords = $postVars['meta_keywords'];
		$metaDescription = $postVars['meta_description'];
		$title = $postVars['title'];
		$description = $postVars['description'];
		$content = $postVars['content'];
		
		$this->addSoftware($name, $accessLevel);
		$this->addSoftwareMetaValues($name, $metaTitle, $metaKeyrwords, $metaDescription);
		$this->addSoftwareContent($name, $title, $description, $content);
		
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?managesoftware">';
	}
	
	private function addSoftwareContent($name, $title, $description, $content){
		$this->database->connect();
		$name = $this->database->escape($name);
		$title = $this->database->escape($title);
		$description = $this->database->escape($description);
		$content = $this->database->escape($content);
		$this->database->prepare(
			"
				insert into software_content_values(software_name, software_title, software_description, software_content) values('$name', '$title', '$description', '$content');
				"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
	
	private function addSoftwareMetaValues($name, $metaTitle, $metaKeywords, $metaDescription){
		$this->database->connect();
		$name = $this->database->escape($name);
		$metaTitle = $this->database->escape($metaTitle);
		$metaDescription = $this->database->escape($metaDescription);
		$metaKeywords = $this->database->escape($metaKeywords);
		$this->database->prepare(
			"
				insert into software_meta_values(software_name, software_meta_title, software_meta_keywords, software_meta_description) values('$name', '$metaTitle', '$metaKeywords', '$metaDescription');
				"
		);
		$this->database->query();
		$this->database->dataOperations();
		header("Location:".SERVER_ROOT."?managesoftware");
	}
	
	private function addSoftware($name, $accessLevel){
		$this->database->connect();
		$name = $this->database->escape($name);
		$accessLevel = $this->database->escape($accessLevel);
		$this->database->prepare(
			"
				insert into software(software_name, software_access_level) values('$name', '$accessLevel');
				"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
}